﻿using System;
using AppTouchScreen.Imaging;

namespace AppTouchScreen.Data
{
    /// <summary>
    /// Represents the base class for element of the store
    /// </summary>
    [Serializable]
    public abstract class StoreElement : IDisposable
    {
        private readonly Category _parent = null;

        internal Category Parent
        {
            get { return _parent; }
        }

        #region Constructors

        private StoreElement() { }

        protected StoreElement(Category parent)
        {
            this._parent = parent;

            if (parent != null)
            {
                parent.Children.Add(this);
            }
        }

        #endregion //Constructors

        #region IDisposable

        public void Dispose()
        {
            if (this._parent != null)
            {
                this._parent.Children.Remove(this);
            }
            else
            {
                throw  new Exception("cannot delete the root element");
            }
        }

        #endregion //IDisposable

        #region Data

        public string Name { get; set; }

        public string Description { get; set; }

        public ImageInfo Image { get; set; }

        #endregion //Data

    }
}
